<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script src="./lib/promise.js"></script>
    <script>
        const p = new Promise((resolve, reject)=>{
           setTimeout(() => {
                // resolve(1)
                reject(2)
                console.log("状态改变之后")
           }, 100);
        }).then(
            value =>{
               console.log("执行回调函数")
               console.log("onResolved1()", value)
               return  4
            },
            reason =>{
                console.log("执行回调函数")
                console.log("onRejected1()", reason)
                return 5
            }
        ).then(
            value =>{
               console.log("onResolved2()", value)
             
            },
            reason =>{
                console.log("onRejected2()", reason)
            }
        )
    // </script>
    // <script>
    //     const p2 = new Promise((resolve, reject)=>{
    //        setTimeout(() => {
    //              resolve(1)
    //             // reject(2)
    //             console.log("状态改变之后")
    //        }, 100);
    //     }).then(
    //         value =>{
    //             console.log("执行回调函数")
    //            console.log("onResolved1()", value)
    //            return 3
    //         },
    //         reason =>{
    //             console.log("执行回调函数")
    //             console.log("onRejected1()", reason)
    //             return new  Promise((resolve, reject)=>{ reject(5)})
    //         }
    //     ).then(
    //         value =>{
    //            console.log("onResolved2()", value)
    //            return new Promise.resolve(8)
    //         },
    //         reason =>{
    //             console.log("onRejected2()", reason)
    //            throw 6
    //         }
    //     ).catch(
           
    //         reason =>{
    //             console.log("onRejected3()", reason)
    //         //    return new Promise (()=>{}) //链式调用中断
    //               return new Promise.reject(7)
    //         }
    //     ).then(
    //         value =>{
    //            console.log("onResolved4()", value)
    //         },
    //         reason =>{
    //             console.log("onRejected4()", reason)
             
    //         }
    //     )
        
      
      
        // const  p3 = new  Promise.reject( 11 ).then(
        //     value =>{
        //         console.log("成功接收数据， 预计数据为11 实际数据为：" + value)

        //     },
        //     reason =>{
        //         console.log(" promise状态为失败，预计接受的数据为11， 实际数据为 ：" + reason)
        //     }
        // ).catch(
        //     reason=> {
        //         console.log( "catch reason " + reason )
        //     }
        // )
        
        const  p6 =  Promise.resolve(13)
        const  p4 = 14 
        const  p5 = new Promise((resolve,reject)=>{
            setTimeout(resolve, 100 , "foo");
        })

        Promise.all([p6,p4,p5]).then(values=>{ console.log("Promise.all 成功", values)})

    </script>
</body>
</html>